﻿#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int main() {
	//打开俩文件
	FILE* pf1 = fopen("data.txt", "w+");
	if (pf1 == NULL) {
		perror("fopen");
		return -1;
	}
	FILE* pf2 = fopen("data_copy.txt", "w+");
	if (pf2 == NULL) {
		perror("fopen");
		return -1;
	}
	//操作
	char arr[100] = { 0 };//其实建议将100换成num，但只在c99中支持
	fputs("what can i say,it's so speachless!is that so?",pf1);
	fseek(pf1, 0, SEEK_END);
	int num = ftell(pf1);
	rewind(pf1);
	//char arr[100] = { 0 };//其实建议将100换成num，但只在c99中支持
	fgets(arr, num+1, pf1);
	if (feof(pf1)) {
		printf("遇到文件末尾了\n");
	}
	else if (ferror(pf1)) {
		printf("读取发⽣了错误\n");
	}
	fputs(arr,pf2);
	//关闭文件
	fclose(pf1);
	pf1 = NULL;
	fclose(pf2);
	pf2 = NULL;
	return 0;
}


